﻿using System;
using System.Web.Mvc;
using DNT.RavenQA.Core.Extensions;

namespace DNT.RavenQA.Web.ViewModels
{
    public class LogOnViewModelBinder : IModelBinder
    {
        public Object BindModel(ControllerContext controllerContext, ModelBindingContext bindingContext)
        {
            var providerName = bindingContext.ValueProvider.GetValue("openid_identifier");
            var returnUrl = bindingContext.ValueProvider.GetValue("ReturnUrl");

            return new LogOnViewModel
                       {
                           ProviderName = providerName.IsNull() ? null : providerName.AttemptedValue,
                           ReturnUrl = returnUrl.IsNull() ? null : returnUrl.AttemptedValue
                       };
        }
    }
}